package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.myapplication.room.entity.Student;
import com.example.myapplication.room.manager.DBEngine;

import java.util.List;

public class DatabaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_database);

        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        Toast.makeText(this, name, Toast.LENGTH_SHORT).show();
        Toast.makeText(this, String.valueOf(intent.getIntExtra("age", 0)), Toast.LENGTH_SHORT).show();
        Toast.makeText(this, (intent.getSerializableExtra("student")).toString(), Toast.LENGTH_SHORT).show();
    }

    public void btn_selectAll(View view) {
        List<Student> students = new DBEngine(this).selectAllStudents();
        students.forEach(item -> Log.i("TAG", "btn_selectAll: " + item.toString()));
    }

    public void btn_insert(View view) {
        Student student1 = new Student("张三", 24);
        Student student2 = new Student("李四", 21);
        Student student3 = new Student("王五", 26);
        new DBEngine(this).insertStudents(student1, student2, student3);
    }

}